function out = estimate_fun_midaco(data1,conv_ma,I,ng,param_ini)

% modified for RAND round 1 revision on July 18, 2022

% Add MIDACO folder 
current_folder = fileparts(mfilename('fullpath'));
addpath(fullfile(current_folder, 'midaco'));

objFun = @(x)problem_function(x,data1, ng, I, conv_ma); %defined below

% lower and upper bounds
lb = repmat(1e-7,1,19);
ub = zeros(1,19);
ub(1) =2;
ub(2) =1; 
ub(3) = 10*max(data1(:,end));
ub(4) = 3000;
ub(5:2*ng+4) = repmat(15,size(5:2*ng+4)); % upper bound the beta density
ub(2*ng+5:2*ng+6) =[1,1];
ub(2*ng+7)  =100; 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%   MAIN PROGRAM   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
key = 'MIDACO_LIMITED_VERSION___[CREATIVE_COMMONS_BY-NC-ND_LICENSE]';

problem.func = objFun;

% Number 1

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Step 1: Problem definition     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% STEP 1.A: Problem dimensions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
problem.o  = 1; % Number of objectives
problem.n  = 19; % Number of variables (in total)
problem.ni = 0; % Number of integer variables (0 <= ni <= n)
problem.m  = 0; % Number of constraints (in total)
problem.me = 0; % Number of equality constraints (0 <= me <= m)

% STEP 1.B: Lower and upper bounds 'xl' & 'xu'
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
problem.xl = lb; 
problem.xu = ub; 

% STEP 1.C: Starting point 'x'
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% problem.x  = problem.xl; % Here for example: 'x' = lower bounds 'xl'
problem.x  = param_ini; % Here for example: 'x' = lower bounds 'xl'


% STEP 1.D: Printing options
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
option.printeval  = 100;  % Print-Frequency for current best solution (e.g. 1000)
option.save2file  = 0;     % Save SCREEN and SOLUTION to TXT-files [ 0=NO/ 1=YES]

% Step 1.E: Choose Parallelization Factor
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
option.parallel = 0;  % Serial: 0 or 1, Parallel: 2,3,4,5,6,7,8...


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Step 2: Options                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% STEP 2.A: Stopping criteria
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
option.maxeval  = 2000;    % Maximum number of function evaluation (e.g. 1000000)
option.maxtime  = 1000; % Maximum time limit in Seconds (e.g. 1 Day = 60*60*24)


% STEP 2.B: Stopping criteria
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

option.param( 1) =  0.1;  % ACCURACY
option.param( 2) =  0;  % SEED
option.param( 3) =  0;  % FSTOP
option.param( 4) =  1;  % ALGOSTOP
option.param( 5) =  6000;  % EVALSTOP
option.param( 6) =  2000;  % FOCUS
option.param( 7) =  0;  % ANTS
option.param( 8) =  0;  % KERNEL
option.param( 9) =  0;  % ORACLE
option.param(10) =  30;  % PARETOMAX
option.param(11) =  0;  % EPSILON
option.param(12) =  0;  % BALANCE
option.param(13) =  0;  % CHARACTER

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%   Call MIDACO solver   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[ solution1 ] = midaco( problem, option, key);


% Number 2

% STEP 2.A: Stopping criteria
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
option.maxeval  = 1000;    % Maximum number of function evaluation (e.g. 1000000)
option.maxtime  = 1000; % Maximum time limit in Seconds (e.g. 1 Day = 60*60*24)


% STEP 2.B: Stopping criteria
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

option.param(1) =  0.01;  % ACCURACY
option.param(2) =  0;  % SEED
option.param(3) =  0;  % FSTOP
option.param(4) =  1;  % ALGOSTOP
option.param(5) =  9000;  % EVALSTOP
option.param(6) =  10;  % FOCUS
option.param(7) =  0;  % ANTS
option.param(8) =  0;  % KERNEL
option.param(9) =  0;  % ORACLE
option.param(10) =  30;  % PARETOMAX
option.param(11) =  0;  % EPSILON
option.param(12) =  0;  % BALANCE
option.param(13) =  0;  % CHARACTER


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%   Call MIDACO solver   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
problem.x = solution1.x;

[ solution2 ] = midaco( problem, option, key);


% Number 3
option.param( 1) =  0.00001;  % ACCURACY
option.param( 6) =  0;  % FOCUS
problem.x        = solution2.x;

[ solution3 ] = midaco( problem, option, key);

% Number 4
option.param( 1) =  0;  % ACCURACY
option.param( 6) =  -100;  % FOCUS
problem.x        = solution3.x;

[ solution4 ] = midaco( problem, option, key);


x= solution4.x;      

[objvalue, lowuest] = ll_fun5([x(1); x(2); x(3); x(4); conv_ma*x(5:ng+4)'; conv_ma*x(5+ng:2*ng+4)';...
    x(2*ng+5:2*ng+6)'; x(2*ng+7)],data1,I);

out = [x lowuest objvalue];

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%   OPTIMIZATION PROBLEM   %%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [ f, g ] = problem_function(x,data1, ng, I, conv_ma)

% Objective functions F(X)
f(1) = ll_fun5([x(1); x(2); x(3); x(4); conv_ma*x(5:ng+4)';...
    conv_ma*x(5+ng:2*ng+4)';...
    x(2*ng+5:2*ng+6)'; x(2*ng+7)],data1,I);
f(1)=-f(1);

g=[];
end
